/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.oai.repositoryManager.items;

import cz.mzk.oai.repositoryManager.collections.CollectionEntity;
import cz.mzk.oai.repositoryManager.oaiId.OaiIdentifierEntity;
import cz.mzk.oai.repositoryManager.sets.SetEntity;
import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author Martin Rehanek (rehan@mzk.cz)
 */
@Entity
@Table(name = "item")
public class ItemEntity implements Serializable {

    @ManyToMany(mappedBy = "items")
    private List<SetEntity> setEntitys;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @JoinColumn(name="oaiid_id", nullable=true, unique = true)
    @OneToOne(cascade = CascadeType.REMOVE)
    private OaiIdentifierEntity oaiId;
    @ManyToOne()
    private CollectionEntity collection;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ItemEntity)) {
            return false;
        }
        ItemEntity other = (ItemEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cz.mzk.oai.repositoryManager.items.ItemEntity[id=" + id + "]";
    }

    /**
     * @return the oaiId
     */
    public OaiIdentifierEntity getOaiId() {
        return oaiId;
    }

    /**
     * @param oaiId the oaiId to set
     */
    public void setOaiId(OaiIdentifierEntity oaiId) {
        this.oaiId = oaiId;
    }

    /**
     * @return the collection
     */
    public CollectionEntity getCollection() {
        return collection;
    }

    /**
     * @param collection the collection to set
     */
    public void setCollection(CollectionEntity collection) {
        this.collection = collection;
    }
}
